package com.njitzx.service.impl;

import com.njitzx.entity.po.Attribute;
import com.njitzx.entity.vo.AttributeVO;
import com.njitzx.entity.vo.Result;
import com.njitzx.mapper.AttributeMapper;
import com.njitzx.service.AttributeService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 属性表 服务实现类
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class AttributeServiceImpl implements AttributeService {

    private final AttributeMapper attributeMapper;

    /**
     * 属性表分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param attribute
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PageInfo<Attribute> findPage(Integer pageNum, Integer pageSize, Attribute attribute) {
        PageHelper.startPage(pageNum, pageSize);
        List<Attribute> attributeList = attributeMapper.select(attribute);
        return new PageInfo<>(attributeList);
    }

    /**
     * 根据主键查询属性表
     *
     * @param
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<Attribute>  findById(Integer catId, String cel) {

        List<Attribute> attributeList = attributeMapper.selectById(catId, cel);
        return attributeList;
    }

    /**
     * 属性表新增
     *
     * @param attribute
     */
    @Override
    public void add(Attribute attribute) {
        attributeMapper.insert(attribute);
    }

    /**
     * 修改属性表
     *
     * @param attribute
     */
    @Override
    public AttributeVO modify(Attribute attribute) {
       attributeMapper.update(attribute);
        AttributeVO attributeVO=attributeMapper.selectAttributeVoById(attribute.getAttrId());
        return attributeVO;
    }

    /**
     * 根据主键删除属性表
     *
     * @param attrId
     */
    @Override
    public void removeById(Serializable attrId) {

            attributeMapper.deleteById(attrId);

    }

    @Override
    public Attribute selectByattrId(Integer attrId) {
        return  attributeMapper.selectByattrId(attrId);
    }
}
